/*
This file is part of AI Agent Feed.

"AI Agent Feed" is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

"AI Agent Feed" is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with "AI Agent Feed".  If not, see <http://www.gnu.org/licenses/>.
 */
package com.feed.processor;

import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.TimeZone;

import org.springframework.beans.factory.annotation.Required;

import com.feed.domain.FeedProvider;
import com.feed.domain.FeedStatusCategory;
import com.feed.domain.Item;

public abstract class AbstractFeedProcessor implements FeedProcessor{


    private String beanName;
    
    private FeedProvider feedSource;
    
    private Integer maxIntervalHours;

	private String cronExpression;
	
	private TimeZone	timeZone;
	
    public TimeZone getTimeZone() {
		return timeZone;
	}

	@Required
	public void setTimeZone(TimeZone timeZone) {
		this.timeZone = timeZone;
	}

	protected AbstractFeedProcessor() {}
    
    public abstract Collection<FeedStatusCategory> processFeed() throws Exception;
    
    protected final void sortItemsByPubDate(List<Item> unsortedItems) {
        if (unsortedItems == null || unsortedItems.size() == 1) return;
        Collections.sort(unsortedItems, Item.PUB_DATE_ORDER);
    }
    
    public String getProcessorName() { return beanName;}
    
    public final void setBeanName(String beanName) {
        this.beanName = beanName;
    }

    protected String getBeanName() {
        return beanName;
    }

    public final void setFeedSource(FeedProvider feedSource) {
        this.feedSource = feedSource;
    }

    public FeedProvider getFeedSource() {
        return feedSource;
    }

    public Integer getMaxIntervalHours() {
    	return maxIntervalHours;
    }
    
    public final void setMaxIntervalHours(Integer maxIntervalHours) {
        this.maxIntervalHours = maxIntervalHours;
    }

    @Override
    public final String toString() {
        return beanName;
    }

	@Required
	public void setCronExpression(String cronExpression) {
		this.cronExpression = cronExpression;
    }

	public String getCronExpression() {
		return cronExpression;
	}

}
